//
// Created by 夏申频 on 17/1/26.
//

#include "ImageCodec.h"

#include "LibJpegCodec.h"
#include "LibCharlsCodec.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern "C"
{
IMAGE_CODEC_IMEXPORT(int) decode(Codec c,ImageCodecContext* context,ImageCodecErr* err){

    memset(err,0,sizeof(ImageCodecErr));

    if(c == CJPEG8)
        return jpegDecode(8,context,err);
    else if(c == CJPEG12)
        return jpegDecode(12,context,err);
    else if(c == CJPEG16)
        return jpegDecode(16,context,err);
    else if(c == CJPLS)
        return jpegLsDecode(context,err);
    err->code = -1;
    strcpy(err->msg,"No such codec");
    return err->code;


}
IMAGE_CODEC_IMEXPORT(int) encode(Codec c,ImageCodecContext* context,ImageCodecErr* err){

    memset(err,0,sizeof(ImageCodecErr));

    if(c == CJPEG8)
        return jpegEncode(8,context,err);
    else if(c == CJPEG12)
        return jpegEncode(12,context,err);
    else if(c == CJPEG16)
        return jpegEncode(16,context,err);
    else if(c == CJPLS)
        return jpegLsEncode(context,err);
    err->code = -1;
    strcpy(err->msg,"No such codec");
    return err->code;
}

IMAGE_CODEC_IMEXPORT(void) freeContextOutput(ImageCodecContext* c){
    if (c->output){
        void * p = *(c->output);
        free(p);
    }
}
};
